package com.ui.basic.resolver.impl;

import java.util.Locale;

import org.springframework.context.support.ResourceBundleMessageSource;

import com.ui.basic.resolver.MessageResolver;

public class MessageResolverImpl implements MessageResolver {
	private ResourceBundleMessageSource messageSource;

	private Locale locale = Locale.getDefault();

	public void setMessageSource(ResourceBundleMessageSource messageSource) {
		this.messageSource = messageSource;
	}

	public String getMessage(String code, String[] args) {
		try {
			return messageSource.getMessage(code, args, locale);
		} catch (Exception e) {
			return code;
		}
	}

	public String getMessage(String code) {
		return getMessage(code, null);
	}

	public void setLocale(Locale locale) {
		this.locale = locale;
	}

}
